using Gateway.IApplication.BaseInput;
using Gateway.IApplication.Role;
using Gateway.IApplication.Role.Input;
using Gateway.IQuery;
using Gateway.IQuery.Role;
using Gateway.IQuery.Role.Request;
using Gateway.IQuery.Role.Result;

namespace Gateway.UI.Api.Controllers;

/// <summary>
/// 角色服务
/// </summary>
public class RoleController : BaseController
{
    private readonly IRoleApp _roleApp;
    private readonly IRoleQuery _roleQuery;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="roleApp"></param>
    /// <param name="roleQuery"></param>
    public RoleController(IRoleApp roleApp, IRoleQuery roleQuery)
    {
        _roleApp = roleApp;
        _roleQuery = roleQuery;
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="input"></param>
    /// <returns>返回主键标识</returns>
    [HttpPost, Route("add")]
    public async Task<string> Add(CreateRoleInput input)
    {
        return await _roleApp.Add(input);
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("update")]
    public async Task<bool> Update(UpdateRoleInput input)
    {
        return await _roleApp.Update(input);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove")]
    public async Task<bool> Remove(RemoveInput input)
    {
        return await _roleApp.Remove(input.Id);
    }

    /// <summary>
    /// 禁用/启用
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("disable")]
    public async Task<bool> Disable(DisableInput input)
    {
        return await _roleApp.Disable(input);
    }

    /// <summary>
    /// 获取详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet, Route("detail/{id}")]
    public async Task<RoleDetailResult> GetDetail(string id)
    {
        return await _roleQuery.GetDetail(id);
    }

    /// <summary>
    /// 项目分页列表
    /// </summary>
    /// <returns></returns>
    [HttpPost, Route("list/page")]
    public async Task<PageResult<RoleDetailResult>> GetPageList(RolePageListRequest request)
    {
        return await _roleQuery.GetPageList(request);
    }

    /// <summary>
    /// 获取可用有效的列表
    /// </summary>
    /// <returns></returns>
    [HttpGet, Route("list/available")]
    public async Task<List<RoleSimpleResult>> GetAvailableList()
    {
        return await _roleQuery.GetAvailableList();
    }

    /// <summary>
    /// 设置角色下的权限（菜单、扩展权限）
    /// </summary>
    /// <param name="input">入参</param>
    /// <returns></returns>

    [HttpPost, Route("auth/set")]
    public async Task<bool> SetMenusAndPermission(SetMenusAndPermissionInput input)
    {
        return await _roleApp.SetMenusAndPermission(input);
    }
}